import time

from selenium import webdriver
from selenium.common import NoSuchElementException
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()

options.page_load_strategy = "normal"  # 等待页面完全加载
# 创建浏览器驱动对象
driver = webdriver.Chrome(options=options)

url = r"https://www.baidu.com/"
driver.get(url)
search = driver.find_element(By.CSS_SELECTOR, "#head_wrapper #kw")
search.send_keys("blbl")
search.send_keys(Keys.ENTER)
time.sleep(3)
driver.find_element(By.LINK_TEXT, "哔哩哔哩").click()

driver.switch_to.window(driver.window_handles[1])
search = driver.find_element(By.XPATH, "//input[@class='nav-search-input']")
search.send_keys("凡人")
search.send_keys(Keys.ENTER)
time.sleep(3)
driver.switch_to.window(driver.window_handles[2])
driver.find_element(By.LINK_TEXT, "立即观看").click()
driver.maximize_window()
driver.switch_to.window(driver.window_handles[3])
time.sleep(3)
driver.find_element(By.XPATH, "//div[@aria-label='全屏']").click()
input("1:")
driver.quit()
